<?php
class Images_AdminController extends Zen_Controller_Admin{
   	
	public function init (){
		$this->storage=new Images_Model_Storage_Local();
		$this->_helper->layout()->disableLayout();
        Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
	}
	
	public function uploadAction(){
		$res=$this->storage->upload('/site/upload/images/','/site/upload/images/thumbs/');
	    echo Zend_Json::encode($res);
	}	
	
	public function cancelAction(){
        $filename=$this->_getParam('file');
        $this->storage->cancel($filename,'/site/upload/images/');
	}
	
	public function loadAction(){
		$id=$this->_getParam('id');
		$id=preg_replace('/\D/','',trim($id));
		$res=$this->storage->load($id);
		$this->_helper->json($res);
	}
	public function updateAction(){
		$params=$this->_getAllParams();
		$id=$this->_getParam('id');
		$id=preg_replace('/\D/','',trim($id));
		unset($params['id']);
		$res=$this->storage->update($id,$params);
		echo Zend_Json::encode($res);
	}
	
	
}